<?php
#
#
# Copyright TEDECO, 2009. http://tedeco.fi.upm.es
#
# This file is part of kumenya.
#
# Kumenya is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Kumenya is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
#
#
#
?>
<?php
class Article
{
	static public function getFields () {
		$dbManager = new DBManager();
		return $DBManager->TableFields (ArticlesTable,Library);
	}
	
	static public function Register ($filledFields) {
		$DBManager = new DBManager();
		$result = $DBManager->ExecuteProcedure ('NewArticle',Library,$filledFields);		
		if ($result)
			Interfaz::Result($DBManager->GetResult());
		else
			Interfaz::Error($DBManager->GetError());
		return $result;		
	}

	static public function Search ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->ExecuteSearchProcedure ('SearchArticles',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function GetStatistics ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->SearchStatistics ('StatisticsArticleSearch',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function SearchAvailable ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->ExecuteSearchProcedure ('SearchAvailableArticles',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function AvailableStatistics ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->SearchStatistics ('AvailableArticlesStatistics',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function SearchLent ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->ExecuteSearchProcedure ('SearchLentArticles',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function LentStatistics ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->SearchStatistics ('LentArticlesStatistics',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function LoansStatistics ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->SearchStatistics ('LoanArticlesSearchStats',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function ReservationsStatistics ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->SearchStatistics ('ReservedArticlesSearchStats',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function SearchReserved ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->ExecuteSearchProcedure ('SearchReservedArticles',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

		static public function ReservedStatistics ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->SearchStatistics ('ReservedArticlesStatistics',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function SearchOnlyReserved ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->ExecuteSearchProcedure ('SearchOnlyReservedArticles',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function OnlyReservedStatistics ($criterias) {
		$DBManager = new DBManager();
		$table = $DBManager->SearchStatistics ('OnlyReservedArticlesStatistics',Library, $criterias);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}
	
	static public function SeeDetails ($identifier) {
		$DBManager = new DBManager();
		$table = $DBManager->ExecuteSearchProcedure ('ArticleDetail',Library, $identifier);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function Modify ($filledFields) {
		$DBManager = new DBManager();
		$result = $DBManager->ExecuteProcedure ('ArticleModification',Library,$filledFields);		
		if ($result)
			Interfaz::Result($DBManager->GetResult());
		else
			Interfaz::Error($DBManager->GetError());
		return $result;		
	}

	static public function ReportByDates ($filledFields) {
		$DBManager = new DBManager();
		$table = $DBManager->ExecuteProcedureReport ('ArticlesLentWhile',Library,$filledFields);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

	static public function ReportByPeople ($filledFields) {
		$DBManager = new DBManager();
		$table = $DBManager->ExecuteProcedureReport ('ArticlesLentTo',Library,$filledFields);
		if (!is_array($table)) {
			Interfaz::Error($DBManager->GetError());
			return FALSE;
		}
		return $table;
	}

}

?>